import { getHeros } from '@/services/hero';

const namespace = 'hero';

const HeroModel = {
  namespace,
  state: {
    heros: [],
    filterKey: 0,
  },
  effects: {
    *fetch({ type, payload }, { put, call, select }) {
      console.log(1111);
      const data = yield call(getHeros);
      yield put({
        type: 'save',
        payload: {
          heros: data,
        },
      });
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      // if (history.location.pathname === '/hero') {
      //   dispatch({
      //     type: 'fetch',
      //   });
      // }
    },
  },
};

export default HeroModel;
